class Solution {
public:
    string minWindow(string s, string t)
    {
        int hashi1[128] = { 0 };
        int minlen = INT_MAX;
        int kinds = 0;
        int begin = -1;
        for (auto e : t)
        {
            hashi1[e]++;
            if (hashi1[e] == 1)
            {
                kinds++;
            }
        }
        int hashi2[128] = { 0 };
        for (int left = 0, right = 0, count = 0; right < s.size(); right++)
        {
            char in = s[right];
            hashi2[in]++;
            if (hashi1[in] == hashi2[in])
            {
                count++;
            }
            while (count == kinds)
            {
                if (right - left + 1 < minlen)
                {
                    begin = left;
                    minlen = right - left + 1;
                }
                char out = s[left];
                if (hashi2[out] == hashi1[out])
                {
                    count--;
                }
                hashi2[out]--;
                left++;
            }
        }
        if (begin == -1)
        {
            return "";
        }
        else return s.substr(begin, minlen);
    }
};